/**
 * Copyright (c) 2012, Camelot and/or its affiliates. All rights reserved.
 * Camelot PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.camelot.ccr.system.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.camelot.ccr.global.dao.genericimpl.GenericHibernateDaoImpl;
import com.camelot.ccr.global.util.Utility;
import com.camelot.ccr.system.dao.SponsorTeamDao;
import com.camelot.ccr.system.persistence.Sponsor;
import com.camelot.ccr.system.persistence.SponsorTeam;

/**
 * <pre>
 * 赞助商车队关系
 * </pre>
 * @author Liu Jun
 * @version V0.1, 2014-5-20 下午10:30:05
 */
@Repository
public class SponsorTeamDaoImpl extends GenericHibernateDaoImpl<SponsorTeam, String> implements SponsorTeamDao {

	/* (non-Javadoc)
	 * @see com.camelot.ccr.system.dao.SponsorTeamDao#delSponsorTeam(java.lang.String)
	 */
	@Override
	public void delSponsorTeam(String teamId) {
		String hql = "delete from SponsorTeam st where st.teamId = ? ";
		getCurrentSession().createQuery(hql).setString(0, teamId).executeUpdate();
	}

	/* (non-Javadoc)
	 * @see com.camelot.ccr.system.dao.SponsorTeamDao#saveBatchSponsorTeam(java.lang.String[], java.lang.String)
	 */
	@Override
	public void saveBatchSponsorTeam(String[] sponsorIds, String teamId) {
		
		delSponsorTeam(teamId);//先清除先前的关系数据
		if(Utility.isNotEmpty(sponsorIds)){
			SponsorTeam st = null;
			for(String sponsorId:sponsorIds){
				st = new SponsorTeam();
				st.setSponsorId(sponsorId);
				st.setTeamId(teamId);
				
				save(st);
			}
		}
		
	}

	/* (non-Javadoc)
	 * @see com.camelot.ccr.system.dao.SponsorTeamDao#getSponsorTeamList(java.lang.String)
	 */
	@Override
	public List<Sponsor> getSponsorTeamList(String teamId) {
		String hql = "select s from SponsorTeam st, Sponsor s where st.teamId = ? and st.sponsorId = s.id " ;
		return (List<Sponsor>) getCurrentSession().createQuery(hql).setString(0, teamId).list();
	}
	
	

	
}
